unit uConfigLocal;

interface

uses Classes, IniFiles, SysUtils, EuConfig;

type
  TConfigLocal = class(TEuConfig)
  private
    FIni: TIniFile;
    function GetDBServidor: string;
    function GetDBPorta: Integer;
    function GetDBBanco: string;
    function GetDBUsuario: string;
    function GetDBSenha: string;
    function GetUltimoComando: Integer;
    procedure SetDBServidor(const Value: string);
    procedure SetDBPorta(const Value: Integer);
    procedure SetDBBanco(const Value: string);
    procedure SetDBUsuario(const Value: string);
    procedure SetDBSenha(const Value: string);
    procedure SetUltimoComando(const Value: Integer);
  protected
    procedure DoRead(const Ident, DefValue: string; var Value: string); override;
    procedure DoWrite(const Ident, Value: string); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property DBServidor: string read GetDBServidor write SetDBServidor;
    property DBPorta: Integer read GetDBPorta write SetDBPorta;
    property DBBanco: string read GetDBBanco write SetDBBanco;
    property DBUsuario: string read GetDBUsuario write SetDBUsuario;
    property DBSenha: string read GetDBSenha write SetDBSenha;
    property UltimoComando: Integer read GetUltimoComando write SetUltimoComando;
  end;

function ConfigLocal: TConfigLocal;

implementation

uses uConst, uFuncoes;

resourcestring
  SDBServidor = 'DBServidor';
  SDBPorta = 'DBPorta';
  SDBBanco = 'DBBanco';
  SDBUsuario = 'DBUsuario';
  SDBSenha = 'DBSenha';
  SUltimoComando = 'UltimoComando';

var
  VarConfigLocal: TConfigLocal = nil;

function ConfigLocal: TConfigLocal;
begin
  if not Assigned(VarConfigLocal) then
    VarConfigLocal := TConfigLocal.Create(nil);
  Result := VarConfigLocal;
end;

{ *** TConfigLocal *** }

{ Private }

function TConfigLocal.GetDBServidor: string;
begin
  Result := ReadString(SDBServidor);
end;

function TConfigLocal.GetDBPorta: Integer;
begin
  Result := ReadInteger(SDBPorta);
end;

function TConfigLocal.GetDBBanco: string;
begin
  Result := ReadString(SDBBanco);
end;

function TConfigLocal.GetDBUsuario: string;
begin
  Result := ReadString(SDBUsuario);
end;

function TConfigLocal.GetDBSenha: string;
begin
  Result := ReadString(SDBSenha);
end;

function TConfigLocal.GetUltimoComando: Integer;
begin
  Result := ReadInteger(SUltimoComando);
end;

procedure TConfigLocal.SetDBServidor(const Value: string);
begin
  WriteString(SDBServidor, Value);
end;

procedure TConfigLocal.SetDBPorta(const Value: Integer);
begin
  WriteInteger(SDBPorta, Value);
end;

procedure TConfigLocal.SetDBBanco(const Value: string);
begin
  WriteString(SDBBanco, Value);
end;

procedure TConfigLocal.SetDBUsuario(const Value: string);
begin
  WriteString(SDBUsuario, Value);
end;

procedure TConfigLocal.SetDBSenha(const Value: string);
begin
  WriteString(SDBSenha, Value);
end;

procedure TConfigLocal.SetUltimoComando(const Value: Integer);
begin
  WriteInteger(SUltimoComando, Value);
end;

{ Protected }

procedure TConfigLocal.DoRead(const Ident, DefValue: string; var Value: string);
begin
  Value := FIni.ReadString('Config', Ident, DefValue);
end;

procedure TConfigLocal.DoWrite(const Ident, Value: string);
begin
  FIni.WriteString('Config', Ident, Value);
end;

{ Public }

constructor TConfigLocal.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FIni := TIniFile.Create(EuAppDir +  'gestao.ini');
end;

destructor TConfigLocal.Destroy;
begin
  FIni.Free;
  inherited;
end;

initialization

finalization
  FreeAndNil(VarConfigLocal);

end.
